// Pipeline Component Library Example
// ----------------------------------
// Colin Bowern (colinbowern@hotmail.com)
// January 2007
//
// Copyright (c) 2007 Colin Bowern
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// * The above copyright notice and this permission notice shall be included in
//   all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#region References
using Microsoft.CommerceServer.Runtime;
using System;
using System.Diagnostics;
#endregion

namespace RockstarGuys.PipelineComponents
{
    /// <summary>
    /// Contains an address associated with an order group.
    /// </summary>
    /// <remarks>
    /// For more information see http://msdn2.microsoft.com/en-us/library/microsoft.commerceserver.runtime.orders.orderaddress.aspx
    /// </remarks>
    [DebuggerDisplay("OrderAddressId = {OrderAddressId}")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1035:ICollectionImplementationsHaveStronglyTypedMembers")]
    public class OrderAddress : Dictionary
    {
        #region Properties
        /// <remarks />
        public Guid? OrderGroupId
        {
            get { return GetGuidFromStringValue(OrderAddress.KeyNames.OrderGroupId); }
            set { this[OrderAddress.KeyNames.OrderGroupId] = (value != null ? value.Value.ToString() : null); }
        }

        /// <remarks />
        public string OrderAddressId
        {
            get { return this[OrderAddress.KeyNames.OrderAddressId] as string; }
            set { this[OrderAddress.KeyNames.OrderAddressId] = value; }
        }

        /// <remarks />
        public string Name
        {
            get { return this[OrderAddress.KeyNames.Name] as string; }
            set { this[OrderAddress.KeyNames.Name] = value; }
        }

        /// <remarks />
        public string FirstName
        {
            get { return this[OrderAddress.KeyNames.FirstName] as string; }
            set { this[OrderAddress.KeyNames.FirstName] = value; }
        }

        /// <remarks />
        public string LastName
        {
            get { return this[OrderAddress.KeyNames.LastName] as string; }
            set { this[OrderAddress.KeyNames.LastName] = value; }
        }

        /// <remarks />
        public string Line1
        {
            get { return this[OrderAddress.KeyNames.Line1] as string; }
            set { this[OrderAddress.KeyNames.Line1] = value; }
        }

        /// <remarks />
        public string Line2
        {
            get { return this[OrderAddress.KeyNames.Line2] as string; }
            set { this[OrderAddress.KeyNames.Line2] = value; }
        }

        /// <remarks />
        public string City
        {
            get { return this[OrderAddress.KeyNames.City] as string; }
            set { this[OrderAddress.KeyNames.City] = value; }
        }

        /// <remarks />
        public string State
        {
            get { return this[OrderAddress.KeyNames.State] as string; }
            set { this[OrderAddress.KeyNames.State] = value; }
        }

        /// <remarks />
        public string RegionCode
        {
            get { return this[OrderAddress.KeyNames.RegionCode] as string; }
            set { this[OrderAddress.KeyNames.RegionCode] = value; }
        }

        /// <remarks />
        public string RegionName
        {
            get { return this[OrderAddress.KeyNames.RegionName] as string; }
            set { this[OrderAddress.KeyNames.RegionName] = value; }
        }

        /// <remarks />
        public string CountryCode
        {
            get { return this[OrderAddress.KeyNames.CountryCode] as string; }
            set { this[OrderAddress.KeyNames.CountryCode] = value; }
        }

        /// <remarks />
        public string CountryName
        {
            get { return this[OrderAddress.KeyNames.CountryName] as string; }
            set { this[OrderAddress.KeyNames.CountryName] = value; }
        }

        /// <remarks />
        public string PostalCode
        {
            get { return this[OrderAddress.KeyNames.PostalCode] as string; }
            set { this[OrderAddress.KeyNames.PostalCode] = value; }
        }

        /// <remarks />
        public string DaytimePhoneNumber
        {
            get { return this[OrderAddress.KeyNames.DaytimePhoneNumber] as string; }
            set { this[OrderAddress.KeyNames.DaytimePhoneNumber] = value; }
        }

        /// <remarks />
        public string EveningPhoneNumber
        {
            get { return this[OrderAddress.KeyNames.EveningPhoneNumber] as string; }
            set { this[OrderAddress.KeyNames.EveningPhoneNumber] = value; }
        }

        /// <remarks />
        public string Email
        {
            get { return this[OrderAddress.KeyNames.Email] as string; }
            set { this[OrderAddress.KeyNames.Email] = value; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="OrderAddress"/> class.
        /// </summary>
        /// <remarks>
        /// The underlying store can be persisted through referencing the InnerList property.
        /// </remarks>
        public OrderAddress() : base()
        {
            this.OrderGroupId = Guid.NewGuid();
            this.OrderAddressId = Guid.NewGuid().ToString();

            this.Name = string.Empty;
            this.FirstName = string.Empty;
            this.LastName = string.Empty;
            this.Line1 = string.Empty;
            this.Line2 = string.Empty;
            this.City = string.Empty;
            this.State = string.Empty;
            this.RegionName = string.Empty;
            this.RegionCode = string.Empty;
            this.PostalCode = string.Empty;
            this.CountryCode = string.Empty;
            this.CountryName = string.Empty;
            this.DaytimePhoneNumber = string.Empty;
            this.EveningPhoneNumber = string.Empty;
            this.Email = string.Empty;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderAddress"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        [CLSCompliant(false)]
        public OrderAddress(IDictionary container) : base(container) { }
        #endregion

        #region Nested Types
        /// <summary>
        /// Keys used to access the properties in the dictionary.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
        public struct KeyNames
        {
            /// <remarks />
            public const string OrderGroupId = "order_group_id";
            /// <remarks />
            public const string OrderAddressId = "address_id";
            /// <remarks />
            public const string Name = "name";
            /// <remarks />
            public const string FirstName = "first_name";
            /// <remarks />
            public const string LastName = "last_name";
            /// <remarks />
            public const string Line1 = "address_line1";
            /// <remarks />
            public const string Line2 = "address_line2";
            /// <remarks />
            public const string City = "city";
            /// <remarks />
            public const string State = "state";
            /// <remarks />
            public const string RegionCode = "region_code";
            /// <remarks />
            public const string RegionName = "region_name";
            /// <remarks />
            public const string CountryCode = "country_code";
            /// <remarks />
            public const string CountryName = "country_name";
            /// <remarks />
            public const string PostalCode = "postal_code";
            /// <remarks />
            public const string DaytimePhoneNumber = "day_time_phone_number";
            /// <remarks />
            public const string EveningPhoneNumber = "evening_phone_number";
            /// <remarks />
            public const string Email = "email";
        }
        #endregion
    }
}
